<template>

  <div>
    <!-- 顶部导航栏 -->
    <van-nav-bar
        title="执行记录"
        left-arrow
        @click-left="sy"
        fixed
    />

    <div style="margin-top: 50px;height: 40px;padding-top: 20px;box-shadow: 0 3px 5px rgba(0,0,0,0.3);">
      <div style="float: left">
        <span style="margin-left: 20px;font-size: 17px">巡检时间</span>
      </div>
      <div style="float: right">
        <span style="margin-right: 150px;font-size: 17px">{{ todayDate }}</span>
      </div>
    </div>

    <div style="border-top: 20px">
      <van-collapse v-model="activeName" accordion>
        <van-collapse-item size="large" style="margin-left: -200px" title="保洁计划" name="1">
          <div v-for="item in data">
            <div class="nrtz">{{ item.code }}
              <van-icon style="margin-left: 100px" name="arrow" @click="handle(item.code)"/>
            </div>
          </div>
        </van-collapse-item>
        <van-collapse-item size="large" style="margin-left: -200px" title="维修计划" name="2">
          <div v-for="item in data1">
            <div class="nrtz">{{ item.code }}
              <van-icon style="margin-left: 100px" name="arrow" @click="handle(item.code)"/>
            </div>
          </div>
        </van-collapse-item>
        <van-collapse-item size="large" style="margin-left: -200px" title="清洁计划" name="3">
          <div v-for="item in data2">
            <div class="nrtz">{{ item.code }}
              <van-icon style="margin-left: 100px" name="arrow" @click="handle(item.code)"/>
            </div>
          </div>
        </van-collapse-item>
      </van-collapse>

    </div>


  </div>

</template>

<script>
export default {
  name: "Workorderbjjl",
  data() {
    return {
      activeName: '1',
      data: [],
      data1: [],
      data2: [],
      pid: 0,
      names: '',
    }
  },

  computed: {
    todayDate() {
      const now = new Date();
      const year = now.getFullYear();
      const month = (now.getMonth() + 1).toString().padStart(2, '0');
      const day = now.getDate().toString().padStart(2, '0');
      return `${year}/${month}/${day}`;
    }
  },

  created() {
    this.userhq();
    this.lsss();

  },
  methods: {

    userhq() {
      const item = localStorage.getItem('aa');

      const aaaa = JSON.parse(item)
      this.names = aaaa['username'];
      let phone = aaaa['phone'];
      this.pid = aaaa['pid']
    },

    handle(code) {
      this.$router.push({path: '/workorderbjjlxq', query: {code: code}})
    },

    sy() {
      this.$router.push('/medical')
    },


    lsss() {
      if (this.pid == 1) {
        this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listcleaning`).then(res => {
          if (res.data.code == 1) {
            this.data = res.data.data;
            this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listrepair`).then(res => {
              if (res.data.code == 1) {
                this.data1 = res.data.data;
                this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listclean`).then(res => {
                  if (res.data.code == 1) {
                    this.data2 = res.data.data;
                  }
                })
              }
            })
          }
        })
      }
      if (this.pid == 2) {
        this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listcleanings?worker=` + this.names).then(res => {
          if (res.data.code == 1) {
            this.data = res.data.data;
            this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listrepairs?worker=` + this.names).then(res => {
              if (res.data.code == 1) {
                this.data1 = res.data.data;
                this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listcleans?worker=` + this.names).then(res => {
                  if (res.data.code == 1) {
                    this.data2 = res.data.data;
                  }
                })
              }
            })
          }
        })
      }
      if (this.pid == 3) {
        this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listcleaningss?name=` + this.names).then(res => {
          if (res.data.code == 1) {
            this.data = res.data.data;
            this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listrepairss?name=` + this.names).then(res => {
              if (res.data.code == 1) {
                this.data1 = res.data.data;
                this.axios.post(`http://localhost:9999/api-cleaning-service/Workorder/listcleanss?name=` + this.names).then(res => {
                  if (res.data.code == 1) {
                    this.data2 = res.data.data;
                  }
                })
              }
            })
          }
        })
      }
    },
  }
}
</script>

<style scoped>

.nrtz {
  //border-bottom: 1px solid black;
  font-size: 17px;
  height: 40px;
  color: black;
  margin-left: 200px;
  //border-top: 1px solid black;

}

</style>